<?php ob_start(); ?>
<?php 	include("config.php");
require_once("auth.php");
?>
<?php 

  $target = "uploaded/"; 
    $tt= "uploaded/"; 

 $target = $target . basename( $_FILES['filePicture']['name']) ; 
 $ok=1;
 $pname=$_POST['txtprdname'];
 $mcat=$_POST['ddlmcategory'];
 $scat=$_POST['ddlscategory'];
	$brand=$_POST['ddlbrand'];
	$model=$_POST['txtmodel'];
	$cost=$_POST['txtcost'];
	$det=$_POST['textdetails'];
	$available=$_POST['$avilable'];
	
$id=$_POST['id'];
 if($_FILES['filePicture']['error'] == 0) {
 $dbLink = new mysqli('localhost','n02557866','s081490','n02557866_db');
// $dbLink = new mysqli('localhost', 'root', '', 'avi');

            if(mysqli_connect_errno()) {
                die("MySQL connection failed: ". mysqli_connect_error());
            }
			
   $name = $dbLink->real_escape_string($_FILES['filePicture']['name']);
            $mime = $dbLink->real_escape_string($_FILES['filePicture']['type']);
            $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['filePicture']['tmp_name']));
            $size = intval($_FILES['filePicture']['size']);

 //This is our size condition 
 if ($uploaded_size > 350000) 
 { 
 echo "Your file is too large.<br>"; 
 $ok=0; 
 } 
 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files<br>"; 
 $ok=0; 
 } 
 //Here we check that $ok was not set to 0 by an error 
 if ($ok==0) 
 { 
 Echo "Sorry your file was not uploaded"; 
 } 
 //If everything is ok we try to upload it 
 else 
 { 
 if(move_uploaded_file($_FILES['filePicture']['tmp_name'], $target)) 
 { 
 		         		echo "<script language=javascript>alert('Success! Your file was successfully added!')</script>";

		  // Gather all required data
          
            // Create the SQL query
			$tt=$tt.$name;
            $query = "Update items set itemname='$pname',details='$det',imagepath='$tt',cost=$cost,subcatname='$scat',maincatname='$mcat',brand='$brand',model='$model',available='$avialable' where itemid=$id";
     
            // Execute the query
            $result = $dbLink->query($query);
            // Check if it was successfull
            if($result) {
				 header("location:displaycomputers.php?updated=updated");
			}
			else
			echo mysqli_error($dbLink);
		}
		}

		}
		else
		{
		 // Make sure the file was sent without errors
         		//echo "<script language=javascript>alert('Success! Your file was successfully added!')<//script>";

                       $query = "Update items set itemname='$pname',details='$det',cost=$cost,subcatname='$scat',maincatname='$mcat',brand='$brand',model='$model',available='$avialable' where itemid=$id";

	
						            $result = mysql_query($query);
            // Check if it was successfull
            if($result) {
				 header("location:displaycomputers.php?updated=updated");
			}
			else
			echo mysql_error();

						
							}
		
        // Close the mysql connection
		
 ?>
<?php ob_flush();
?>